﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using System.Collections;

namespace MxTol.Models
{
    /// <summary>
    /// 学生实体类
    /// </summary>
    [ActiveRecord(Table = "Student")]
    public class Student : ActiveRecordBase
    {
        /// <summary>
        /// 学生信息主键
        /// </summary>
        [PrimaryKey("id")]
        public Guid ID { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [Property("name")]
        public string Name { get; set; }

        /// <summary>
        /// 电话号码
        /// </summary>
        [Property("phone")]
        public string Phone { get; set; }

        /// <summary>
        /// 账号
        /// </summary>
        [Property("account")]
        public string Account { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        [Property("psword")]
        public string Psword { get; set; }

        /// <summary>
        /// 安卓客户端硬件机器码
        /// </summary>
        [Property("android_code")]
        public string AndroidCode { get; set; }

        /// <summary>
        /// 是否在线  0:离线  1：在线
        /// </summary>
        [Property("is_online")]
        public byte IsOnline { get; set; }

        /// <summary>
        /// 上一次登录时间
        /// </summary>
        [Property("last_login_time")]
        public Nullable<DateTime> LastLoginTime { get; set; }

        /// <summary>
        /// 该条记录添加时间
        /// </summary>
        [Property("add_time")]
        public DateTime AddTime { get; set; }

        /// <summary>
        /// 获取所有学生
        /// </summary>
        public static List<Student> GetAllStudent()
        {
            List<Student> list = null;

            IList students = FindAll(typeof(Student));
            if (students != null && students.Count > 0)
            {
                list = new List<Student>();
                foreach (var student in students)
                {
                    list.Add(((Student)student));
                }
                return list;
            }

            return list;
        }

        /// <summary>
        /// 根据主键获取学生
        /// </summary>
        public static Student GetStudentByID(Guid id)
        {
            Student student = (Student)FindByPrimaryKey(typeof(Student), id);
            if (student != null)
            {
                return student;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 删除所有学生
        /// </summary>
        public static void DeleteAll()
        {
            DeleteAll(typeof(Student));
        }
    }
}
